package org.example.leetCode;

/**
 * @author Administrator
 */
public class LengthOfLastWord {
    public int lengthOfLastWord(String s) {
        int length = 0;
        if (s.trim() == null) {
            return 0;
        }
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            int temp = 0;
            if (chars[i] != ' ') {
                temp++;
                if (i == chars.length - 1) {
                    return temp;
                } else if (chars[i + 1] == ' ') {
                    length = temp;
                    temp = 0;
                }
            }
        }
        return length;
    }
}
